package com.lz.filter.servletFilter;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import javax.servlet.FilterConfig;
import javax.servlet.*;
import java.io.IOException;

@Component
@Slf4j
public class MyFilter implements Filter {


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
        // 初始化过滤器
        log.info("初始化过滤器");
    }


    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info("进入自定义过滤器,获取==>{}", "模拟过滤器,他会在Servlet之前执行");

        chain.doFilter(request, response);
//
        // 在请求处理之后执行
        log.info("进入自定义过滤器,获取==>{}", "模拟过滤器,他会在Servlet之后执行");
    }

    @Override
    public void destroy() {
        // 清理资源
        log.info("销毁过滤器");
    }
}